# coding=utf-8
from flask_wtf import csrf
from flask import make_response, current_app
from flask.blueprints import Blueprint


html = Blueprint('html', __name__)


@html.route("/<regex('.*'):file_name>")
def html_file(file_name):
    if not file_name:
        file_name = 'index.html'

    if file_name != 'favicon.ico':
        file_name = 'html/' + file_name

    response = make_response(current_app.send_static_file(file_name))
    # 生成csrf_token
    csrf_token = csrf.generate_csrf()
    # 向客户端浏览器的cookie中写入csrf_token
    response.set_cookie('csrf_token', csrf_token)
    return response

